<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <button>按钮</button>
  <script>
    var btn = document.querySelector('button')
    var i = 0
    btn.onclick = function () {
      ++i
      if (i % 2) {
        document.body.style.backgroundColor = 'red'
      } else {
        document.body.style.backgroundColor = ''
      }
    }
  </script>

</html>